﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace QLNS
{
    public partial class frmLog : Form
    {
        public frmLog()
        {
            InitializeComponent();
        }

        public SqlConnection getConnect()
        {
            return new SqlConnection(@"Data Source=THANGVUONG\SQLEXPRESS;Initial Catalog=Quanlynhansu;Integrated Security=True");
        }
        public DataTable CheckLogin(string user, string pass)
        {
            string sql = "Select * from Dangnhap where Tendangnhap ='" + user + "'and Matkhau ='" + pass + "'";
            SqlConnection con = getConnect();
            SqlDataAdapter adap = new SqlDataAdapter(sql, con);
            DataTable dt = new DataTable();
            adap.Fill(dt);
            return dt;
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt = CheckLogin(txtUser.Text, txtPass.Text);
            if (dt.Rows.Count > 0)
            {
                this.Hide();
                MainForm frmMain = new MainForm();
                frmMain.ShowDialog();
                this.Close();
            }
            else
            {
                lbstt.Text = "Đăng nhập không thành công!";
            }
        }

        private void btnLogout_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void frmLog_Load(object sender, EventArgs e)
        {
            this.AcceptButton = btnLogin;
        }

    }
}
